#version 410 core

// Declare all the semantics
#define ATTR_POSITION	0
#define ATTR_NORMAL		1
#define ATTR_COLOR		2

#define VERT_POSITION	0
#define VERT_NORMAL		1
#define VERT_COLOR		2
#define VERT_INSTANCE	3

#define FRAG_COLOR		0

uniform vec4 Color;

layout(location = VERT_INSTANCE) in float vDepth;

layout(location = FRAG_COLOR, index = 0) out vec4 fColor;

vec3 gamma(vec3 color)
{
    return pow(color, vec3(0.5f));
}

vec3 fog(vec3 color, vec3 fogColor, float depth, float density)
{
	const float e = 2.718281828f;
    float f = pow(e, -pow(depth * density, 2));
    
    return mix(fogColor, color, f);
}

void main()
{
	vec3 fragWithFog = fog(Color.xyz, vec3(0.8f), vDepth, 0.004f);
	fColor = vec4(gamma(fragWithFog), 1.0f);
}
